package mes.kanban.util;

import java.util.List;

/**
 * 分页
 * @author gjy
 *
 * 2018年2月27日下午6:26:51
 */
@SuppressWarnings({"rawtypes"})
public class PageBean {
	
	public void init(){
		
		this.isFirstPage = isFirstPage();
		this.isLastPage = isLastPage();
		this.hasNextPage = isHasNextPage();
		this.hasPreviousPage = isHasPreviousPage();
		
	}
	

	//要返回的某一页的记录列表
	private List list;
	
	//总记录数 
	private Integer allCounts;
	
	//总页数 
	private Integer totalPage;
	
	//当前页 
	private Integer currentPage;
	
	//每页记录数 
	private Integer pageSize;
	
	//是否为第一页 
	private boolean isFirstPage;
	
	//是否为最后一页 
	private boolean isLastPage;
	
	//是否有前一页 
	private boolean hasPreviousPage;
	
	//是否有下一页
	private boolean hasNextPage;

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public Integer getAllCounts() {
		return allCounts;
	}

	public void setAllCounts(Integer allCounts) {
		this.allCounts = allCounts;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	
	@Override
	public String toString() {
		return "PageBean [list=" + (IsNotNullValit.CollectionIsNotNull(list)?list.size():"总共有0条记录") + ", allCounts=" + allCounts
				+ ", totalPage=" + totalPage + ", currentPage=" + currentPage
				+ ", pageSize=" + pageSize + ", isFirstPage=" + isFirstPage
				+ ", isLastPage=" + isLastPage + ", hasPreviousPage="
				+ hasPreviousPage + ", hasNextPage=" + hasNextPage + "]";
	}
	
	/**
	 * 判断分页信息并初始化
	 */
	// 如是当前页是第1页
	public boolean isFirstPage(){
		
		return this.currentPage == 1;
		
	}
	
	//如果当前页是最后一页
	public boolean isLastPage(){
		
		return this.currentPage == this.totalPage;
	}
	
	//只要当前页不是第1页
	public boolean isHasPreviousPage(){
		
		return this.currentPage != 1;
	}
	
	//只要当前页不是最后1页
	public boolean isHasNextPage(){
		
		return this.currentPage != this.totalPage;
	}
	
	/**
	 * 计算总页数
	 * @param pageSize 每页记录数 
	 * @param allRow 总记录数 
	 * @return 总页数 
	 */
	public static int countTotalSize(int pageSize,int allRow){
		
		if(pageSize+""==null || pageSize == 0)
			pageSize = 1;
		
		int totalSize = allRow%pageSize ==0 ? allRow/pageSize:allRow/pageSize+1;
		
		return totalSize;
	}
	
	/** 
	* 计算当前页开始记录 
	* @param pageSize 每页记录数 
	* @param currentPage 当前第几页 
	* @return 当前页开始记录号 
	*/ 
	public static Integer countOffset(int pageSize,int currentPage){
		
		int offSet = pageSize * (currentPage-1);
		
		return offSet;
	}
	

	
	
}
